unit UnitDolg;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids, jpeg, ExtCtrls;

type
  TDolg = class(TForm)
    StringGrid1: TStringGrid;
    Image2: TImage;
    Image1: TImage;
    procedure FormShow(Sender: TObject);
    procedure OtborDolg(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Image2Click(Sender: TObject);
    procedure Image2MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Image2MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Image2MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Image1Click(Sender: TObject);
    procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
  private
    { Private declarations }
  public
  Xc,Yc:integer;
  nom:Byte;
    { Public declarations }
  end;

var
  Dolg: TDolg;

implementation

uses Unit1;

{$R *.dfm}
procedure TDolg.OtborDolg(Sender: TObject);
var i:integer;
s:string;
begin

for i:=1 to Form1.StringGrid1.RowCount-1 do
begin

if Form1.StringGrid1.Cells[2,i]<>'' then
begin
if strtoint(Form1.StringGrid1.Cells[2,i])<0 then
begin
s:=Unit1.vkl[i];
if dolg.StringGrid1.Cells[0,dolg.StringGrid1.RowCount-1]<>'' then  {Если первая строка пуста}
begin
StringGrid1.RowCount:=dolg.StringGrid1.RowCount+1;
StringGrid1.Cells[0,dolg.StringGrid1.RowCount-1]:=Form1.StringGrid1.Cells[0,i];
StringGrid1.Cells[1,dolg.StringGrid1.RowCount-1]:=Form1.StringGrid1.Cells[2,i];
StringGrid1.Cells[2,dolg.StringGrid1.RowCount-1]:=s;
end
else
begin
dolg.StringGrid1.Cells[0,dolg.StringGrid1.RowCount-1]:=Form1.StringGrid1.Cells[0,i];
dolg.StringGrid1.Cells[1,dolg.StringGrid1.RowCount-1]:=Form1.StringGrid1.Cells[2,i];
dolg.StringGrid1.Cells[2,dolg.StringGrid1.RowCount-1]:=s;
end;

end;
end;

end;

end;

procedure TDolg.FormShow(Sender: TObject);
begin
Stringgrid1.Cells[0,0]:='Телефон абонента';
Stringgrid1.ColWidths[0]:=100;
Stringgrid1.Cells[1,0]:='Остаток';
Stringgrid1.ColWidths[1]:=50;
Stringgrid1.Cells[2,0]:='Активность';
Stringgrid1.ColWidths[1]:=50;

OtborDolg(Sender);
end;

procedure TDolg.FormClose(Sender: TObject; var Action: TCloseAction);
var i,j:integer;
begin

for i:=0 to Dolg.StringGrid1.ColCount-1 do
begin
for j:=1 to Dolg.StringGrid1.RowCount-1 do
begin
Dolg.StringGrid1.Cells[i,j]:='';
end;
end;
Dolg.StringGrid1.RowCount:=2;
end;

procedure TDolg.Image2Click(Sender: TObject);
begin
Close;
end;

procedure TDolg.Image2MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
image2.Picture.LoadFromFile('image\button4.jpg');
end;

procedure TDolg.Image2MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
image2.Picture.LoadFromFile('image\button3.jpg');
end;

procedure TDolg.Image2MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
image2.Picture.LoadFromFile('image\button2.jpg');
end;

procedure TDolg.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
image2.Picture.LoadFromFile('image\button2.jpg');
image1.Picture.LoadFromFile('image\button14.jpg');
end;

procedure TDolg.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
image1.Picture.LoadFromFile('image\button9.jpg');
end;

procedure TDolg.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
image1.Picture.LoadFromFile('image\button8.jpg');
end;

procedure TDolg.Image1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
image1.Picture.LoadFromFile('image\button14.jpg');
end;

procedure TDolg.Image1Click(Sender: TObject);
var i:integer;
a:abonent;
tel,tel1:string;
begin
for i:=1 to stringgrid1.RowCount-1 do
begin
tel:=form1.StringGrid1.Cells[0,i];
tel1:=StringGrid1.Cells[0,Yc];
if tel=tel1 then
begin nom:=i end;
end;

Form1.PoiskSApis(Sender,nom-1);
a:=ab;
a.Active:='Выкл';
write(F,a);
closefile(F);
Form1.Sagruska(Sender,2);
ShowMessage('Обслуживание абонента отключено');

end;

procedure TDolg.StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
  var CanSelect: Boolean);
begin
Xc:=Acol;
Yc:=ARow;
end;

end.
